package cn.jf.modules.system.mapper;

import cn.jf.modules.system.entity.SysUserRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

	@Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleByUserName(@Param("username") String username);
	@Select("select id,user_id as userId,role_id as roleId from sys_user_role where user_id =#{userId}")
	List<SysUserRole> getUserRoleByUserID(@Param("userId") String userId);
	@Select("select id,user_id as userId,role_id as roleId from sys_user_role where user_id =#{userId} and role_id = #{roleId}")
	SysUserRole getUserRoleByUserIDRoleID(@Param("userId") String userId,@Param("roleId") String roleId);
	@Update(value = "delete from sys_user_role where user_id =#{userId} and role_id = #{roleId}")
	void deltUserRoleByUserIDRoleID(@Param("userId") String userId,@Param("roleId") String roleId);
	@Update(value = "delete from sys_user_role where user_id =#{userId}")
	void deltUserRoleByUserID(@Param("userId") String userId);
	@Update(value = "delete from sys_user_role where role_id =#{roleId}")
	void deltUserRoleByRoleId(@Param("roleId") String roleId);
	@Select("select user_id from sys_user_role where role_id =#{roleId}")
	List<String> getUserIdByRoleId(@Param("roleId")String roleId);
}
